package com.chb.wordcount;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.util.StringUtils;

/**
 * 
 *
 */
public class WCMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
	/**
	 * �÷���ѭ�����ã����ļ���split��û��ȡһ�е���һ�Σ� 
	 * �Ѹ��е����ڵ��±�Ϊkey, ����Ϊvalue
	 * 
	 * mapper���������ϴ�ƣ� ���飬 �����reducer
	 * �����У� ϴ�ƺͷ�����Ĭ�ϵ�
	 * ������ʱ���ÿ���
	 */
	@Override
	protected void map(LongWritable key, Text value, Context context)
			throws IOException, InterruptedException {
		String[] words = StringUtils.split(value.toString(), ' ');
		for (String w : words) {
			if(w==null && "".equals(w)){
				return;
			}else {
				context.write(new Text(w), new IntWritable(1));
			}
		}

	}
}
